﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Dsl.Ped.Controls.ProjectiveControl"
    xmlns:converters="clr-namespace:Dsl.Ped.Controls.ProjectiveControl.Converters">

    <converters:ViewModeToVisibilityConverter x:Key="viewModeToVisibilityConverter"/>
    
    <Style TargetType="{x:Type local:ProjectionContainerControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ProjectionContainerControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <ContentControl Content="{TemplateBinding SelectedItem}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:TransitionControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:TransitionControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:ProjectiveControl}">
        <Setter Property="ContextMenu">
            <Setter.Value>
                <ContextMenu ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}">
                    <ContextMenu.Template>
                        <ControlTemplate>
                            <ListBox ItemsSource="{Binding Items, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProjectiveControl}}"
                                                      SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProjectiveControl}}"
                                                      SelectionMode="Single"
                                     MinWidth="100">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>

                                            <Image Grid.Column="0" Width="10" Height="10" Margin="0,0,5,0" Source="{Binding Image}"/>
                                            <TextBlock Grid.Column="1" Text="{Binding Title}"/>
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </ControlTemplate>
                    </ContextMenu.Template>
                </ContextMenu>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ProjectiveControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            x:Name="controlBorder">
                        <ContentControl Grid.Row="1"                                            
                                        x:Name="PART_ContentControl"
                                        Cursor="{TemplateBinding Cursor}" 
                                        HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
                                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                        FontFamily="{TemplateBinding FontFamily}" 
                                        FontSize="{TemplateBinding FontSize}" 
                                        FontStretch="{TemplateBinding FontStretch}" 
                                        Foreground="{TemplateBinding Foreground}" 
                                        Margin="{TemplateBinding Margin}" 
                                        VerticalAlignment="{TemplateBinding VerticalAlignment}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <ListBox ItemsSource="{Binding Items, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProjectiveControl}}"
                                         SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProjectiveControl}}"
                                         SelectionMode="Single"
                                         x:Name="listBox"
                                         Visibility="{TemplateBinding ViewMode, Converter={StaticResource viewModeToVisibilityConverter}}"
                                         Grid.Row="0">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>

                                                <Image Grid.Column="0" Width="10" Height="10" Margin="0,0,5,0" Source="{Binding Image}"/>
                                                <TextBlock Grid.Column="1" Text="{Binding Title}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>

                                <ContentPresenter Content="{TemplateBinding SelectedItem}"
                                                  Grid.Row="1"/>
                            </Grid>
                            <ContentControl.ContextMenu>
                                <ContextMenu ItemsSource="{Binding Path=Items, RelativeSource={RelativeSource TemplatedParent}}">
                                    <ContextMenu.Template>
                                        <ControlTemplate>                                            
                                            <ListBox ItemsSource="{Binding Items, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProjectiveControl}}"
                                                      SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProjectiveControl}}"
                                                      SelectionMode="Single">
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <Grid>
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="Auto"/>
                                                                <ColumnDefinition Width="*"/>
                                                            </Grid.ColumnDefinitions>

                                                            <Image Grid.Column="0" Width="10" Height="10" Margin="0,0,5,0" Source="{Binding Image}"/>
                                                            <TextBlock Grid.Column="1" Text="{Binding Title}"/>
                                                        </Grid>                                                      
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>                                            
                                        </ControlTemplate>
                                    </ContextMenu.Template>
                                </ContextMenu>
                            </ContentControl.ContextMenu>
                        </ContentControl>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="local:ProjectiveControl.IsProjectiveControlActivated" Value="True">
                            <Setter Property="Border.BorderBrush" Value="LightBlue" TargetName="controlBorder"/>
                            <Setter Property="Border.BorderThickness" Value="1" TargetName="controlBorder"/>
                            <Setter Property="Border.Background" Value="LightBlue" TargetName="controlBorder"/>
                            <Setter Property="ContentControl.Background" Value="LightBlue" TargetName="PART_ContentControl"/>
                            <!--<Setter Property="ListBox.Visibility" Value="Visible" TargetName="listBox"/>-->
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:ProjectionControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ProjectionControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <ContentControl Content="{TemplateBinding Content}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
